<template>
  <div class="icons-swiper">
    <swiper ref="mySwiper"
            :options="swiperOption">
      <!-- slides -->
      <swiper-slide v-for="(item_, index) in pages"
                    :key="index">
        <div class="icon-box"
             v-for="(item,index) in item_"
             :key="item.id + index">
          <div class="icon-img-box">
            <img :src="item.imgUrl"
                 alt="">
          </div>
          <p class="icon-dese">{{item.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>

  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  data () {
    return {
      iconsList: [
        {
          id: '001',
          desc: '景点门票',
          imgUrl: '//s.qunarzz.com/homenode/images/touchheader/hotel.png'
        },
        {
          id: '002',
          desc: '景点门票',
          imgUrl: '//s.qunarzz.com/homenode/images/touchheader/hotel.png'
        },
        {
          id: '003',
          desc: '景点门票',
          imgUrl: '//s.qunarzz.com/homenode/images/touchheader/hotel.png'
        },
        {
          id: '004',
          desc: '景点门票',
          imgUrl: '//s.qunarzz.com/homenode/images/touchheader/hotel.png'
        },
        {
          id: '005',
          desc: '景点门票',
          imgUrl: '//s.qunarzz.com/homenode/images/touchheader/hotel.png'
        },
        {
          id: '006',
          desc: '景点门票',
          imgUrl: '//s.qunarzz.com/homenode/images/touchheader/hotel.png'
        },
        {
          id: '007',
          desc: '景点门票',
          imgUrl: '//s.qunarzz.com/homenode/images/touchheader/hotel.png'
        },
        {
          id: '008',
          desc: '景点门票',
          imgUrl: '//s.qunarzz.com/homenode/images/touchheader/hotel.png'
        },
        {
          id: '009',
          desc: '景点门票',
          imgUrl: '//s.qunarzz.com/homenode/images/touchheader/hotel.png'
        },
        {
          id: '009',
          desc: '景点门票',
          imgUrl: '//s.qunarzz.com/homenode/images/touchheader/hotel.png'
        }
      ],
      swiperOption: {
        autoplayDisableOnInteraction: false,
        loop: true,
        autoplay: 2000
      }
    }
  },
  computed: {
    // icons: function () {
    //   let arr = []
    //   let len = this.iconsList.length
    //   let group = Math.ceil(len / 8)
    //   let num = 0
    //   let shu = 8
    //   for (var i = 0; i < group; i++) {
    //     arr.push([])
    //     for (var j = num; j < len; j++) {
    //       if (j % (shu * (i + 1)) === 0 && j !== 0) {
    //         num += 8
    //         break
    //       } else {
    //         arr[i].push(this.iconsList[j])
    //       }
    //     }
    //   }
    //   console.log(arr)
    //   return arr
    // }
    pages: function () {
      let arr = []
      this.iconsList.forEach(function (item, index) {
        let ind = Math.floor(index / 8)
        if (!arr[ind]) {
          arr.push([])
        }
        arr[ind].push(item)
      })
      return arr
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~@/assets/styles/variables.styl';
@import '~@/assets/styles/mixins.styl';

.icons-swiper {
  width: 100%;
  height: 0;
  padding-bottom: 50%;
  margin: 0.2rem 0;

  // background-color: #eee;
  .icon-box {
    position: relative;
    float: left;
    width: 25%;
    height: 0;
    padding-bottom: 25%;

    // background-color: red;
    .icon-img-box {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0.44rem;

      img {
        display: block;
        margin: 0 auto;
        height: 100%;
      }
    }

    .icon-dese {
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      height: 0.44rem;
      line-height: 0.44rem;
      text-align: center;
      color: $darkTxt;
      ellipsis();
    }
  }
}
</style>
